package net.borlis.processor.dao.entity;

import net.borlis.processor.dao.entity.common.AuditedEntity;
import net.borlis.processor.dao.entity.common.BaseEntity;

import javax.persistence.*;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

/**
 * Created by borlis on 24.12.2014.
 */
@Entity
@Table(name = "mw_node")
public class MwNodeEntity extends BaseEntity implements AuditedEntity {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private BigInteger id;

    @Column(name = "node_name")
    private String name;

    @Column(name = "address")
    private String address;

    @Column(name = "uuid", nullable = false)
    @org.hibernate.annotations.Type(type="org.hibernate.type.PostgresUUIDType")
    private UUID uuid;

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "started_on", nullable = false, columnDefinition = "DATETIME")
    private Date startedOn;

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "last_active_on", nullable = false, columnDefinition = "DATETIME")
    private Date lastActiveOn;

    @Basic
    @Column(name = "is_active", nullable = false)
    private Boolean active;

    public MwNodeEntity() {
        super();
        lastActiveOn = Calendar.getInstance().getTime();
    }

    public BigInteger getId() {
        return id;
    }

    public void setId(BigInteger id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public Date getStartedOn() {
        return this.startedOn != null ? new Date(this.startedOn.getTime()) : null;
    }

    public void setStartedOn(Date startedOn) {
        this.startedOn = (startedOn != null ? new Date(startedOn.getTime()) : null);
    }

    public Date getLastActiveOn() {
        return this.lastActiveOn != null ? new Date(this.lastActiveOn.getTime()) : null;
    }

    public void setLastActiveOn(Date lastActiveOn) {
        this.lastActiveOn = (lastActiveOn != null ? new Date(lastActiveOn.getTime()) : null);
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }
}
